<?php

namespace app\admin\model;

use app\extra\HasManyJoin;
use think\Model;

/**
 * 模型公共文件
 * */
class Common extends Model
{

    /**
     * HAS MANY 关联定义查询
     * @access public
     * @param string $model      模型名
     * @param string $foreignKey 关联外键
     * @param string $localKey   当前模型主键
     * @return HasManyJoin {@link HasManyJoin}
     */
    public function hasManyJoin($model, $foreignKey = '', $localKey = '')
    {
        // 记录当前关联信息
        $model      = $this->parseModel($model);
        $localKey   = $localKey ?: $this->getPk();
        $foreignKey = $foreignKey ?: $this->getForeignKey($this->name);
        return new HasManyJoin($this, $model, $foreignKey, $localKey);
    }

}
